﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Entity;
using DataControls;

namespace GiaoVien_QuanLy_DeTai
{
    public partial class HEDAOTAO_Form : Form
    {
        HEDAOTAO hedaotao = new HEDAOTAO();
        DataBaseAccess dataBaseAccess = new DataBaseAccess();
        HEDAOTAO_Data hedaotao_Data = new HEDAOTAO_Data();
        public HEDAOTAO_Form()
        {
            InitializeComponent();
        }

        private void HEDAOTAO_Form_Load(object sender, EventArgs e)
        {
            txtMaHDT.Text = "HDT";
            txtTenHDT.Text = "";
        }

        private void btnHienThi_Click(object sender, EventArgs e)
        {
            hedaotao.hienthi_HeDaoTao(dtgHDT);
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            if (txtMaHDT.Text == "")
            {
                txtMaHDT.Focus();
                MessageBox.Show("Ban chua dien ma so He Dao Tao");
                return;
            }
            else if (hedaotao_Data.kiemtra_TenHeDaoTao(txtTenHDT.Text.ToString()))
            {
                txtTenHDT.Focus();
                MessageBox.Show("Ban nhap trung Ten He Dao Tao");
                return;
            }
            else if (hedaotao_Data.kiemtra_MaHeDaoTao(txtMaHDT.Text.ToString()))
            {
                txtMaHDT.Focus();
                MessageBox.Show("Ban nhap trung Ma He Dao Tao");
                return;
            }

            else if (txtTenHDT.Text == "")
            {
                txtTenHDT.Focus();
                MessageBox.Show("Ban chua dien ten He Dao Tao");
                return;
            }
            
            

            else
            {

                hedaotao.maHDT = txtMaHDT.Text.ToString();
                hedaotao.tenHDT = txtTenHDT.Text.ToString();

                hedaotao.them_HeDaoTao(hedaotao);
                hedaotao.hienthi_HeDaoTao(dtgHDT);

                txtMaHDT.Text = "HDT";
                txtTenHDT.Text = "";
            }
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (txtMaHDT.Text == "")
            {
                txtMaHDT.Focus();
                MessageBox.Show("Ban chua dien ma so He Dao Tao");
                return;
            }
            else if (hedaotao_Data.kiemtraMaHDT_LopHoc(txtMaHDT.Text.ToString()))
            {
                MessageBox.Show("Ban chua xoa He Dao Tao trong Lop Hoc");
                return;
            }
            else
            {

                hedaotao.xoa_HeDaoTao(txtMaHDT.Text.ToString());
                hedaotao.hienthi_HeDaoTao(dtgHDT);

                txtMaHDT.Text = "HDT";
                txtTenHDT.Text = "";
            }
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            if (txtMaHDT.Text == "")
            {
                txtMaHDT.Focus();
                MessageBox.Show("Ban chua dien ma so He Dao Tao");
                return;
            }
            else if (txtTenHDT.Text == "")
            {
                txtTenHDT.Focus();
                MessageBox.Show("Ban chua dien ten He Dao Tao");
                return;
            }

            else
            {
                hedaotao.maHDT = txtMaHDT.Text.ToString();
                hedaotao.tenHDT = txtTenHDT.Text.ToString();
                hedaotao.sua_HeDaoTao(hedaotao);
                hedaotao.hienthi_HeDaoTao(dtgHDT);

                txtMaHDT.Text = "HDT";
                txtTenHDT.Text = "";
            }
        }

        private void dtgHDT_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            dtgHDT.AllowUserToAddRows = false;
            int dong = e.RowIndex;
            txtMaHDT.Text = dtgHDT.Rows[dong].Cells[0].Value.ToString();
            txtTenHDT.Text = dtgHDT.Rows[dong].Cells[1].Value.ToString();
            
        }

        private void txtMaHDT_MouseClick(object sender, MouseEventArgs e)
        {
            txtMaHDT.Text = "HDT";
            txtTenHDT.Text = "";
        }


    }
}
